package gl;

import gl.android.biyiqing.R;
import gl.view.RippleBackground;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class SplashActivity extends Activity {
	final Handler handler = new Handler();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);

		final RippleBackground rippleBackground = (RippleBackground) findViewById(R.id.content);
		final RippleBackground rippleBackground1 = (RippleBackground) findViewById(R.id.content1);


		rippleBackground.startRippleAnimation();
		final ImageView button = (ImageView) findViewById(R.id.centerImage);
		final Animation loadAnimation = AnimationUtils.loadAnimation(
				getApplicationContext(), android.R.anim.fade_out);
		final Animation loadAnimation2= AnimationUtils.loadAnimation(
				getApplicationContext(), android.R.anim.fade_out);
		loadAnimation2.setDuration(2000);
		loadAnimation.setDuration(1500);
		loadAnimation.setFillAfter(true);
		loadAnimation2.setFillAfter(true);
		button.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {

			}
		});
		handler.postDelayed(new Runnable() {
			@Override
			public void run() {
				rippleBackground.stopRippleAnimation();
			}
		}, 3000);
		handler.postDelayed(new Runnable() {
			@Override
			public void run() {
				rippleBackground1.startRippleAnimation();

				findViewById(R.id.bg).startAnimation(loadAnimation2);
				
				button.startAnimation(loadAnimation);
				
			}
		}, 2000);
		handler.postDelayed(new Runnable() {
			@Override
			public void run() {
				rippleBackground1.setVisibility(View.GONE);
				try {
					onBackPressed();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}, 4000);

	}
	@Override
	protected void onPause() {
		super.onPause();
		handler.removeCallbacksAndMessages(null);
		finish();
	}

}
